<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="root">
			<h2>今天{{time}}邹宜臻吃的是{{food1}}</h2>
			<button @click="change">切换食物</button>
			<hr>
			<h3>{{numbers.a}}</h3>
			<button @click="numbers.a++">增加</button><br>
			<h3>{{numbers.b}}</h3>
			<button @click="numbers.b++">增加</button>
		</div>
		<script type="text/javascript">
			let lunch = '',
				dinner = ''
			const vm = new Vue({
				el: '#root',
				data: {
					isLunch: true,
					food: true,
					numbers: {
						a: 1,
						b: 1
					}
				},
				methods: {
					change() {
						this.isLunch = !this.isLunch
						this.food = !this.food
					}
				},
				computed: {
					time() {
						return this.isLunch ? '中午' : '晚上'
					},
					food1() {
						return this.food ? '臭豆腐' : '腐乳'
					},
				},
				watch: {
					// time: {
					// 	handler(newValue, oldValue) {
					// 		dinner = newValue
					// 		lunch = oldValue
					// 		// console.log(`当前的天气是${newValue},之前的天气是${oldValue}`);
					// 	}
					// },
					time(newValue, oldValue) {
						dinner = newValue
						lunch = oldValue
					},
					food1: {
						handler(newValue, oldValue) {
							console.log(
								`当前的时间是${dinner},${dinner}邹宜臻吃的是${newValue};之前的时间是${lunch},${lunch}邹宜臻吃的是${oldValue}`
							);
						}
					},
					numbers: {
						deep: true,
						handler() {
							console.log('numbers改变了');
						}
					}
				}
			})
		</script>
	</body>
</html>
